package com.irdstudio.efp.esb.api.service.common.repository;

import com.irdstudio.efp.loan.service.facade.AccLoanService;
import com.irdstudio.efp.loan.service.vo.AccLoanVO;
import com.irdstudio.efp.loan.service.vo.AccLoanVOBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static com.irdstudio.efp.console.common.ConsoleConstant.ACC_STATUS_10;
import static com.irdstudio.efp.console.common.ConsoleConstant.ACC_STATUS_14;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/12/4
 * 功能描述:
 * 修改日期:2019/12/4
 * 修改描述:
 */
@Service("accLoanRepository")
public class AccLoanRepository {
    @Autowired
    @Qualifier("accLoanService")
    private AccLoanService accLoanService;

    public int getAccLoanByCertTypeOrCode(String certType, String certCode) {
        int num1 = Optional.ofNullable(accLoanService.queryAccLoanListByCondition(AccLoanVOBuilder.anAccLoanVO().withCertCode(certCode).withCertType(certType).withAccountStatus(ACC_STATUS_10).build())).orElseGet(ArrayList::new).size();
        int num2 = Optional.ofNullable(accLoanService.queryAccLoanListByCondition(AccLoanVOBuilder.anAccLoanVO().withCertCode(certCode).withCertType(certType).withAccountStatus(ACC_STATUS_14).build())).orElseGet(ArrayList::new).size();
        return num1+num2;
    }
}
